package algorithm.leetcode

object BreakfastStratage {
    fun breakfastNumber(staple: IntArray, drinks: IntArray, x: Int): Int {
        staple.sort()
        drinks.sort()
        var count = 0
        var l1 = 0
        var l2 = drinks.size - 1
        while (l1 < staple.size && l2 >= 0){
            if(staple[l1] + drinks[l2] <= x){
                //此处l2是索引，个数是l2+1，当前满足，则前面的都满足
                count += l2+1
                count %= 1000000007
                l1++
            }else{
                l2--
            }
        }
        return count
    }
}

fun main() {
//    println(976918302 % 1000000007)
    println(BreakfastStratage.breakfastNumber(intArrayOf(10,20,5), intArrayOf(5,5,2), 15))
}